// pages/workerCode/done.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sub:{sn:'',price:'',note:'',imgs:[]},
    serverUrl:'',
    serverHeader:{},
    card: {address:{},user:{},date:{},imgs:[]},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    this.setData({
      serverUrl:wx.util.interfaceUrl()+"upload",
      serverHeader:{
        'Deer-Device-Type':'wxapp',
        'Deer-Api-Version':wx.util.ver,
        'Deer-Api-Token': wx.util.getToken()
      }
    })
    if(e.sn){
      this.setData({
        'sub.sn':e.sn
      })
    }
    this.load();
  },
  async load(){
    let res=await wx.util.post("task/index",this.data.sub);
    if(res.data.total==0){
      wx.util.toast('订单不存在！');
      return;
    }
    this.setData({
      card:res.data.data[0]
    })
  },
  async done(){
    await wx.util.confirm("是否确认服务完成？","如需补差价，请提醒客户支付");
    await wx.util.post("task/done",this.data.sub,false);
    wx.util.toast('操作成功');
    await wx.util.sleep(800);
    wx.navigateBack();
  },
  setInput(e) {
    let key = e.currentTarget.dataset.key;
    this.setData({
      [key]: e.detail
    })
  },
  result: function(s) {
    let e=s.detail;
    this.setData({
      'sub.imgs':e.imgArr
    })
  },
  remove: function(e) {
    this.data.sub.imgs.splice(e.detail.index,1);
    this.setData({
      'sub.imgs':this.data.sub.imgs
    })
  }
})